/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs575.dbentities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author bms
 */
@Entity
@Table(name = "task_user", catalog = "tasks_management", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TaskUser.findAll", query = "SELECT t FROM TaskUser t"),
    @NamedQuery(name = "TaskUser.findByTaskId", query = "SELECT t FROM TaskUser t WHERE t.taskUserPK.taskId = :taskId"),
    @NamedQuery(name = "TaskUser.findByUserId", query = "SELECT t FROM TaskUser t WHERE t.taskUserPK.userId = :userId"),
    @NamedQuery(name = "TaskUser.findByRead", query = "SELECT t FROM TaskUser t WHERE t.read = :read"),
    @NamedQuery(name = "TaskUser.findByEdit", query = "SELECT t FROM TaskUser t WHERE t.edit = :edit"),
    @NamedQuery(name = "TaskUser.findByDelete", query = "SELECT t FROM TaskUser t WHERE t.delete = :delete"),
    @NamedQuery(name = "TaskUser.findBySetPermission", query = "SELECT t FROM TaskUser t WHERE t.setPermission = :setPermission"),
    @NamedQuery(name = "TaskUser.findByComplete", query = "SELECT t FROM TaskUser t WHERE t.complete = :complete")})
public class TaskUser implements Serializable, ITaskUser {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TaskUserPK taskUserPK;
    @Basic(optional = false)
    @Column(name = "read", nullable = false)
    private boolean read;
    @Basic(optional = false)
    @Column(name = "edit", nullable = false)
    private boolean edit;
    @Basic(optional = false)
    @Column(name = "delete", nullable = false)
    private boolean delete;
    @Basic(optional = false)
    @Column(name = "set_permission", nullable = false)
    private boolean setPermission;
    @Basic(optional = false)
    @Column(name = "complete", nullable = false)
    private boolean complete;
    @JoinColumn(name = "user_id", referencedColumnName = "user_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private User user;
    @JoinColumn(name = "task_id", referencedColumnName = "task_id", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Task task;

    public TaskUser() {
    }

    public TaskUser(TaskUserPK taskUserPK) {
        this.taskUserPK = taskUserPK;
    }

    public TaskUser(TaskUserPK taskUserPK, boolean read, boolean edit, boolean delete, boolean setPermission, boolean complete) {
        this.taskUserPK = taskUserPK;
        this.read = read;
        this.edit = edit;
        this.delete = delete;
        this.setPermission = setPermission;
        this.complete = complete;
    }

    public TaskUser(int taskId, int userId) {
        this.taskUserPK = new TaskUserPK(taskId, userId);
    }

    public TaskUserPK getTaskUserPK() {
        return taskUserPK;
    }

    public void setTaskUserPK(TaskUserPK taskUserPK) {
        this.taskUserPK = taskUserPK;
    }

    @Override
    public boolean getRead() {
        return read;
    }

    public void setRead(boolean read) {
        this.read = read;
    }

    @Override
    public boolean getEdit() {
        return edit;
    }

    public void setEdit(boolean edit) {
        this.edit = edit;
    }

    @Override
    public boolean getDelete() {
        return delete;
    }

    public void setDelete(boolean delete) {
        this.delete = delete;
    }

    @Override
    public boolean getSetPermission() {
        return setPermission;
    }

    public void setSetPermission(boolean setPermission) {
        this.setPermission = setPermission;
    }

    @Override
    public boolean getComplete() {
        return complete;
    }

    public void setComplete(boolean complete) {
        this.complete = complete;
    }

    @Override
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (taskUserPK != null ? taskUserPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TaskUser)) {
            return false;
        }
        TaskUser other = (TaskUser) object;
        if ((this.taskUserPK == null && other.taskUserPK != null) || (this.taskUserPK != null && !this.taskUserPK.equals(other.taskUserPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cs575.dbentities.TaskUser[ taskUserPK=" + taskUserPK + " ]";
    }
    
}
